import type { ISurveyDB } from "@/types";
import {
  isPicTitleDescStatusArr,
  isStringArray,
  isValueStatusArr,
  type IJSStatusItemOptions,
  type IJSStatusItemText,
} from "@/types/editProps";
import type {
  GetOptionsItemStatus,
  IJsonSchemaStatusBase,
  IJSStatusItemRateSetting,
} from "@/types/editProps";
import type { TableColumnCtx } from "element-plus";

/**
 * * 获取状态(纯文本类型)
 * @param props 文本状态
 * @returns { string } 文本状态
 */
export const getTextStatus = (props: IJSStatusItemText) => {
  if (props) {
    return props.status;
  }
};

/**
 * * 获取状态(字符串数组类型)
 * @description { value: string; label: string; }[]
 * @param props 字符串数组状态
 * @returns 字符串数组状态
 */
export const getStringArrStatus = (props: IJSStatusItemOptions) => {
  if (props && isStringArray(props.status)) {
    return props.status;
  }
};

/**
 * * 获取状态(值数组类型)
 * @description { value: string; label: string; }[]
 * @param props 值数组状态
 * @returns 值数组状态
 */
export const getValueStatusArr = (props: IJSStatusItemOptions) => {
  if (props && isValueStatusArr(props.status)) {
    return props.status;
  }
};

/**
 * * 获取状态(图片标题描述数组类型)
 * @description { picTitle: string; picDesc: string; value: string; }[]
 * @param props 图片标题描述数组状态
 * @returns 图片标题描述数组状态
 */
export const getPicTitleDescStatusArr = (props: IJSStatusItemOptions) => {
  if (props && isPicTitleDescStatusArr(props.status)) {
    return props.status;
  }
};

/**
 * * 获取当前状态索引
 * @param props 字符串数组状态
 * @returns 当前状态索引
 */
export const getActiveCurrentStatusIndex = (props: IJSStatusItemOptions) => {
  // console.log(props);
  if (props && isStringArray(props.status)) {
    return props.currentStatusIndex;
  }
};

/**
 * * 获取当前状态
 * @param props 字符串数组状态
 * @returns 当前状态
 */
export const getActiveCurrentStatus = <T extends keyof IJsonSchemaStatusBase>(
  props: IJSStatusItemOptions | undefined,
): GetOptionsItemStatus<T> | undefined => {
  if (props?.status && props?.currentStatusIndex !== undefined) {
    return props.status[props.currentStatusIndex] as GetOptionsItemStatus<T>;
  }
};

/**
 * * 获取评分设置
 * @param props 评分设置
 * @returns 评分设置
 */
export const getRateStatus = (props: IJSStatusItemRateSetting) => {
  console.log(props);
  if (props) {
    return {
      isUse: props.isUse,
      status: props.status,
    };
  }
};

// 将时间戳转为日期格式
// 日期格式化函数
export function formatDate(
  row: ISurveyDB,
  column: TableColumnCtx<ISurveyDB>,
  cellValue: number,
) {
  const options: Intl.DateTimeFormatOptions = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
  };
  return new Intl.DateTimeFormat("zh-CN", options).format(new Date(cellValue));
};
